/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.weixin.web;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.aspectj.apache.bcel.classfile.annotation.NameValuePair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.weixin.entity.OssWeixin;
import com.thinkgem.jeesite.modules.weixin.service.OssWeixinService;

/**
 * 微信Controller
 * @author hui.li
 * @version 2017-04-23
 */
@Controller
@RequestMapping(value = "${adminPath}/weixin/ossWeixin")
public class OssWeixinController extends BaseController {

	@Autowired
	private OssWeixinService ossWeixinService;
	
	@ModelAttribute
	public OssWeixin get(@RequestParam(required=false) String id) {
		OssWeixin entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = ossWeixinService.get(id);
		}
		if (entity == null){
			entity = new OssWeixin();
		}
		return entity;
	}
	
	@RequiresPermissions("weixin:ossWeixin:view")
	@RequestMapping(value = {"list", ""})
	public String list(OssWeixin ossWeixin, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<OssWeixin> page = ossWeixinService.findPage(new Page<OssWeixin>(request, response), ossWeixin); 
		model.addAttribute("page", page);
		return "modules/weixin/ossWeixinList";
	}

	@RequiresPermissions("weixin:ossWeixin:view")
	@RequestMapping(value = "form")
	public String form(OssWeixin ossWeixin, Model model) {
		model.addAttribute("ossWeixin", ossWeixin);
		return "modules/weixin/ossWeixinForm";
	}

	@RequiresPermissions("weixin:ossWeixin:edit")
	@RequestMapping(value = "save")
	public String save(OssWeixin ossWeixin, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, ossWeixin)){
			return form(ossWeixin, model);
		}
		ossWeixinService.save(ossWeixin);
		addMessage(redirectAttributes, "保存微信成功");
		return "redirect:"+Global.getAdminPath()+"/weixin/ossWeixin/?repage";
	}
	
	@RequiresPermissions("weixin:ossWeixin:edit")
	@RequestMapping(value = "delete")
	public String delete(OssWeixin ossWeixin, RedirectAttributes redirectAttributes) {
		ossWeixinService.delete(ossWeixin);
		addMessage(redirectAttributes, "删除微信成功");
		return "redirect:"+Global.getAdminPath()+"/weixin/ossWeixin/?repage";
	}
	
	
}